Fix a bunch of warnings
authorYehuda Katz <wycats@gmail.com>
Mon, 5 May 2014 21:33:28 +0000 (14:33 -0700)
committerYehuda Katz <wycats@gmail.com>
Mon, 5 May 2014 21:33:28 +0000 (14:33 -0700)
src/bin/cargo-compile.rs
src/bin/cargo-read-manifest.rs
src/cargo/core/source.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_read_manifest.rs
src/cargo/ops/cargo_rustc.rs
src/cargo/sources/path.rs

index f83993bded093cd7c256c26b228c93d42c1be7f2..12ab5107eb2a4ffe31940645ae049df7136f4f7d 100644 (file)
@@ -7,7 +7,7 @@ extern crate serialize;
 
 use cargo::ops::cargo_compile::compile;
 use cargo::{CargoResult,ToCargoError};
-use hammer::{FlagDecoder,FlagConfig,FlagConfiguration,HammerError};
+use hammer::{FlagDecoder,FlagConfig,HammerError};
 use serialize::Decodable;
 
 #[deriving(Eq,Clone,Decodable,Encodable)]
index 54ca728fb5bae8b46d8fdcee5b6d82f0cc11051b..5007e42e3ed09004da0ef60255038ed10b34a963 100644 (file)
@@ -2,10 +2,28 @@
 #![allow(deprecated_owned_vector)]
 
 extern crate cargo;
+extern crate serialize;
+extern crate hammer;
 
-use cargo::execute_main_without_stdin;
-use cargo::ops::cargo_read_manifest::execute;
+use cargo::{CargoResult,execute_main_without_stdin};
+use cargo::ops::cargo_read_manifest::read_manifest;
+use cargo::core::Manifest;
+use hammer::FlagConfig;
+
+#[deriving(Decodable,Eq,Clone,Ord)]
+pub struct ReadManifestFlags {
+    manifest_path: ~str
+}
+
+impl FlagConfig for ReadManifestFlags {}
 
 fn main() {
     execute_main_without_stdin(execute);
 }
+
+fn execute(flags: ReadManifestFlags) -> CargoResult<Option<Manifest>> {
+    match read_manifest(flags.manifest_path) {
+        Ok(manifest) => Ok(Some(manifest)),
+        Err(e) => Err(e)
+    }
+}
index 243d52dbbf72479f91b5f6a3fa73b467e6946053..78677f3ae29b17d17bbe749a39c8e9cd1908fa68 100644 (file)
@@ -1,4 +1,3 @@
-use std::fmt;
 use core::{NameVer,Package};
 use CargoResult;
 
index e904595491c6b60cdf27059cabddbd2253938bf7..9405acde314d32b141a7ea55fd4dc8dbfdd9ad98 100644 (file)
  *    b. Compile each dependency in order, passing in the -L's pointing at each previously compiled dependency
  */
 
-use std;
 use std::vec::Vec;
-use serialize::{Decodable};
-use std::io;
-use std::io::BufReader;
-use std::io::process::{Process,ProcessExit,ProcessOutput,InheritFd,ProcessConfig};
 use std::os;
 use util::config;
 use util::config::{all_configs,ConfigValue};
-use cargo_read_manifest = ops::cargo_read_manifest::read_manifest;
 use core::resolver::resolve;
 use core::package::PackageSet;
-use core::Package;
 use core::source::Source;
 use core::dependency::Dependency;
 use sources::path::PathSource;
 use ops::cargo_rustc;
-use {CargoError,ToCargoError,CargoResult};
-
+use {CargoError,CargoResult};
 
 pub fn compile(manifest_path: &str) -> CargoResult<()> {
-    let manifest = try!(cargo_read_manifest(manifest_path));
-
     let configs = try!(all_configs(os::getcwd()));
     let config_paths = configs.find(&("paths".to_owned())).map(|v| v.clone()).unwrap_or_else(|| ConfigValue::new());
 
@@ -58,46 +48,7 @@ pub fn compile(manifest_path: &str) -> CargoResult<()> {
 
     let resolved = try!(resolve(deps.as_slice(), &registry));
 
-    cargo_rustc::compile(&resolved);
-
-    Ok(())
-    //call_rustc(~BufReader::new(manifest_bytes.as_slice()))
-}
-
-
-fn read_manifest(manifest_path: &str) -> CargoResult<Vec<u8>> {
-    Ok((try!(exec_with_output("cargo-read-manifest", ["--manifest-path".to_owned(), manifest_path.to_owned()], None))).output)
-}
+    try!(cargo_rustc::compile(&resolved));
 
-fn call_rustc(mut manifest_data: ~Reader:) -> CargoResult<()> {
-    let data: &mut Reader = manifest_data;
-    try!(exec_tty("cargo-rustc", [], Some(data)));
     Ok(())
 }
-
-fn exec_with_output(program: &str, args: &[~str], input: Option<&mut Reader>) -> CargoResult<ProcessOutput> {
-    Ok((try!(exec(program, args, input, |_| {}))).wait_with_output())
-}
-
-fn exec_tty(program: &str, args: &[~str], input: Option<&mut Reader>) -> CargoResult<ProcessExit> {
-    Ok((try!(exec(program, args, input, |config| {
-        config.stdout = InheritFd(1);
-        config.stderr = InheritFd(2);
-    }))).wait())
-}
-
-fn exec(program: &str, args: &[~str], input: Option<&mut Reader>, configurator: |&mut ProcessConfig|) -> CargoResult<Process> {
-    let mut config = ProcessConfig::new();
-    config.program = program;
-    config.args = args;
-    configurator(&mut config);
-
-    println!("Executing {} {}", program, args);
-
-    let mut process = try!(Process::configure(config).to_cargo_error(|e: io::IoError| format!("Could not configure process: {}", e), 1));
-
-    input.map(|mut reader| io::util::copy(&mut reader, process.stdin.get_mut_ref()));
-
-    Ok(process)
-}
-
index b2c0c60b4b3d864be62028f1a91a8288adfa7d16..0666c666bbc9f1fcb3f199d926799533d96bda32 100644 (file)
@@ -1,32 +1,11 @@
 use toml;
-use hammer::FlagConfig;
-use serialize::Decoder;
 use toml::from_toml;
-use {CargoResult,ToCargoError,core};
 use core::manifest::{SerializedManifest,Manifest};
+use {CargoResult,ToCargoError};
 
-
-#[deriving(Decodable,Eq,Clone,Ord)]
-pub struct ReadManifestFlags {
-    manifest_path: ~str
-}
-
-impl FlagConfig for ReadManifestFlags {}
-
-pub fn read_manifest(manifest_path: &str) -> CargoResult<core::Manifest> {
-    match execute(ReadManifestFlags { manifest_path: manifest_path.to_owned() }) {
-        Ok(manifest) => Ok(manifest.unwrap()),
-        Err(e) => Err(e)
-    }
-}
-
-pub fn execute(flags: ReadManifestFlags) -> CargoResult<Option<core::Manifest>> {
-    let manifest_path = flags.manifest_path;
+pub fn read_manifest(manifest_path: &str) -> CargoResult<Manifest> {
     let root = try!(toml::parse_from_file(manifest_path.clone()).to_cargo_error(format!("Couldn't parse Toml file: {}", manifest_path), 1));
-
     let toml_manifest = try!(from_toml::<SerializedManifest>(root.clone()).to_cargo_error(|e: toml::Error| format!("Couldn't parse Toml file: {:?}", e), 1));
 
-    Manifest::from_serialized(manifest_path.as_slice(), &toml_manifest).map(|manifest| {
-        Some(manifest)
-    })
+    Manifest::from_serialized(manifest_path.as_slice(), &toml_manifest)
 }
index c2c51a5e189469bf3096e2bf3cba543310a67593..8216d6eb62e77f630ca7e142353ef201b462e14d 100644 (file)
@@ -3,50 +3,56 @@ use std::os::args;
 use std::io;
 use std::io::process::{Process,ProcessConfig,InheritFd};
 use std::path::Path;
-use {CargoResult,CargoError,ToCargoError,NoFlags,core};
+use {CargoResult,CargoError,ToCargoError,NoFlags};
 use core;
 use util;
 
 type Args = Vec<~str>;
 
-pub fn compile(pkgs: &core::PackageSet) {
+pub fn compile(pkgs: &core::PackageSet) -> CargoResult<()> {
     let sorted = match pkgs.sort() {
         Some(pkgs) => pkgs,
-        None => fail!("Could not perform topsort on PackageSet")
+        None => return Err(CargoError::new("Circular dependency detected".to_owned(), 1))
     };
 
     for pkg in sorted.iter() {
-        compile_pkg(pkg, pkgs);
+        try!(compile_pkg(pkg, pkgs));
     }
+
+    Ok(())
 }
 
 
-fn compile_pkg(pkg: &core::Package, pkgs: &core::PackageSet) {
+fn compile_pkg(pkg: &core::Package, pkgs: &core::PackageSet) -> CargoResult<()> {
     // Build up the destination
     let src = pkg.get_root().join(Path::new(pkg.get_source().path.as_slice()));
     let target = pkg.get_root().join(Path::new(pkg.get_target()));
 
     // First ensure that the directory exists
-    mk_target(&target);
+    try!(mk_target(&target).to_cargo_error(format!("Could not create the target directory {}", target.display()), 1));
 
     // compile
-    rustc(pkg.get_root(), &src, &target, deps(pkg, pkgs));
+    try!(rustc(pkg.get_root(), &src, &target, deps(pkg, pkgs)));
+
+    Ok(())
 }
 
 fn mk_target(target: &Path) -> io::IoResult<()> {
     io::fs::mkdir_recursive(target, io::UserRWX)
 }
 
-fn rustc(root: &Path, src: &Path, target: &Path, deps: &[core::Package]) {
+fn rustc(root: &Path, src: &Path, target: &Path, deps: &[core::Package]) -> CargoResult<()> {
     let mut args = Vec::new();
 
     build_base_args(&mut args, src, target);
     build_deps_args(&mut args, deps);
 
-    util::process("rustc")
+    try!(util::process("rustc")
         .cwd(root.clone())
         .args(args.as_slice())
-        .exec();
+        .exec().to_cargo_error(format!("Couldn't execute rustc {}", args.connect(" ")), 1));
+
+    Ok(())
 }
 
 fn build_base_args(dst: &mut Args, src: &Path, target: &Path) {
index da2a03aa9afa10244cb7129777e8c8be929e7094..5f907459d1cdaf943c7c66a8f2a25baaf9209bb6 100644 (file)
@@ -12,16 +12,6 @@ impl PathSource {
     pub fn new(paths: Vec<Path>) -> PathSource {
         PathSource { paths: paths }
     }
-
-    fn map<T>(&self, callback: |&Path| -> CargoResult<T>) -> CargoResult<Vec<T>> {
-        let mut ret = Vec::with_capacity(self.paths.len());
-
-        for path in self.paths.iter() {
-            ret.push(try!(callback(path)));
-        }
-
-        Ok(ret)
-    }
 }
 
 impl Source for PathSource {
@@ -36,11 +26,11 @@ impl Source for PathSource {
         }).collect())
     }
 
-    fn download(&self, name_ver: &[NameVer])  -> CargoResult<()>{
+    fn download(&self, _: &[NameVer])  -> CargoResult<()>{
         Ok(())
     }
 
-    fn get(&self, packages: &[NameVer]) -> CargoResult<Vec<Package>> {
+    fn get(&self, _: &[NameVer]) -> CargoResult<Vec<Package>> {
         Ok(self.paths.iter().filter_map(|path| {
             match read_manifest(path) {
                 Ok(ref manifest) => Some(Package::from_manifest(manifest)),